package com.sweets.look.util;

import android.content.Context;
import android.util.Base64;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import com.sweets.look.adapter.HistoryItem;
import com.sweets.look.preference.PreferenceManager;
import com.sweets.look.ui.browser.BookmarkManager;

import org.json.JSONObject;

public final class InfoUtils {
    public InfoUtils() {
        super();
    }

    public static String getBookmarkBase64Code(Context context) {
        String v0 = null;
        try {
            FileInputStream v4 = context.openFileInput("bookmarks.dat");
            byte[] v1 = new byte[v4.available()];
            v4.read(v1);
            String v6 = new String(v1, "UTF-8");
            v4.close();
            v0 = URLEncoder.encode(new String(Base64.encode(v6.trim().getBytes(), 0)), "utf-8");
        } catch (Exception v7) {
        }

        return v0;
    }

    public static String getInfoBase64Code(Context context, String str) {
        String v2 = null;
        try {
            v2 = URLEncoder.encode(new String(Base64.encode(str.trim().getBytes(), 0)), "utf-8");
        } catch (Exception v3) {
        }

        return v2;
    }

    public static String getSettingsBase64Code(Context context) {
        String v5 = null;
        try {
            PreferenceManager v2 = PreferenceManager.getInstance();
            JSONObject v3 = new JSONObject();
            v3.put("AdBlock", v2.getAdBlockEnabled());
            v3.put("anim", v2.getAnimEnabled());
            v3.put("block3rdpartycookies", v2.getBlock3rdPartyCookiesEnabled());
            v3.put("localAdb", v2.getLocalAdBlockEnabled());
            v3.put("bookmarksStye", v2.getBookmarksStyle());
            v3.put("blockimages", v2.getBlockImagesEnabled());
            v3.put("cache", v2.getClearCacheExit());
            v3.put("clearCookiesExit", v2.getClearCookiesExitEnabled());
            v3.put("clearFormdataExit", v2.getClearFormdataExitEnabled());
            v3.put("clearHistoryExit", v2.getClearHistoryExitEnabled());
            v3.put("clearStorageExit", v2.getClearWebStorageExitEnabled());
            v3.put("colormode", v2.getColorModeEnabled());
            v3.put("cookies", v2.getCookiesEnabled());
            v3.put("donottrack", v2.getDoNotTrackEnabled());
            v3.put("download", v2.getDownloadDirectory());
            v3.put("enableflash", v2.getFlashSupport());
            v3.put("fullscreen", v2.getFullScreenEnabled());
            v3.put("hidestatus", v2.getHideStatusBarEnabled());
            v3.put("hideunderline", v2.getHideUnderlineEnabled());
            v3.put("home", v2.getHomepage());
            v3.put("imageswitch", v2.getImageSwitchEnabled());
            v3.put("incognitoMode", v2.getIncognitoModeEnabled());
            v3.put("incognitocookies", v2.getIncognitoCookiesEnabled());
            v3.put("java", v2.getJavaScriptEnabled());
            v3.put("location", v2.getLocationEnabled());
            v3.put("nightmode", v2.getNightModeEnabled());
            v3.put("opentimes", v2.getOpenTimes());
            v3.put("overviewmode", v2.getOverviewModeEnabled());
            v3.put("newwindows", v2.getPopupsEnabled());
            v3.put("removeidentifyingheaders", v2.getRemoveIdentifyingHeadersEnabled());
            v3.put("renderMode", v2.getRenderingMode());
            v3.put("requestdesktopsite", v2.getRuequstDesktopSiteEnabled());
            v3.put("restoreclosed", v2.getRestoreLostTabsEnabled());
            v3.put("saveformdata", v2.getSaveFormDataEnabled());
            v3.put("passwords", v2.getSavePasswordsEnabled());
            v3.put("screenOrientation", v2.getScreenOrientation());
            v3.put("search", v2.getSearchChoice());
            v3.put("searchhint", v2.getSearchHintEnabled());
            v3.put("searchurl", v2.getSearchUrl());
            v3.put("textencoding", v2.getTextEncodingChoice());
            v3.put("textreflow", v2.getTextReflowEnabled());
            v3.put("textsize", v2.getTextSize());
            v3.put("urlbox", v2.getUrlBoxChoice());
            v3.put("agentchoose", v2.getUserAgentChoice());
            v3.put("wideviewport", v2.getUseWideViewportEnabled());
            v3.put("volume", v2.getVolumeScroll());
            v3.put("webintent", v2.getWebIntentEnabled());
            v3.put("wakelock", v2.getWakeLockEnabled());
            v3.put("keyback", v2.getKeyBackChoice());
            v3.put("keyforward", v2.getKeyForwardChoice());
            v3.put("keyhome", v2.getKeyHomeChoice());
            v3.put("keymenu", v2.getKeyMenuChoice());
            v3.put("keytab", v2.getKeyTabChoice());
            v3.put("gesturetoolbarleft", v2.getGestureToolbarLeftChoice());
            v3.put("gesturetoolbarright", v2.getGestureToolbarRightChoice());
            v3.put("searchtimes", v2.getSearchTimes());
            v3.put("linkstimes", v2.getLinksTimes());
            v3.put("ui", v2.getUIChoice());
            v3.put("addontranslate", v2.getAddonsTranslateEnabled());
            v3.put("addonviewsource", v2.getAddonsViewSourceEnabled());
            v3.put("addonscreenshot", v2.getAddonsScreenshotEnabled());
            v3.put("quickback", v2.getQuickBackEnabled());
            v5 = URLEncoder.encode(new String(Base64.encode(v3.toString().trim().getBytes(), 0)), "utf-8");
        } catch (Exception v6) {
        }

        return v5;
    }

    public static String getTextBase64(String str) {
        if (str == null) {
            str = "";
        }

        return Base64.encodeToString(str.getBytes(), 0);
    }

    public static String getTextOrign(String str) {
        if (str == null) {
            str = "";
        }

        return new String(Base64.decode(str.getBytes(), 0));
    }

    public static boolean synchronizeDataFromCloud(Context context, String json) {
        boolean v12 = false;
        try {
            JSONObject v8 = new JSONObject(json);
            String v2 = new String(Base64.decode(v8.optString("bookmark"), 0));
            if (!v2.isEmpty()) {
                ArrayList v1 = new ArrayList();
                BufferedReader v3 = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(
                        v2.getBytes())));
                while (true) {
                    String v7 = v3.readLine();
                    if (v7 == null) {
                        break;
                    }

                    JSONObject v11 = new JSONObject(v7);
                    HistoryItem v6 = new HistoryItem();
                    v6.setTitle(v11.getString("title"));
                    v6.setUrl(v11.getString("url"));
                    v6.setFolder(v11.getString("folder"));
                    v6.setOrder(v11.getInt("order"));
                    ((List) v1).add(v6);
                }

                v3.close();
                BookmarkManager.overwriteBookmarkList(context, ((List) v1));
            }

            String v13 = new String(Base64.decode(v8.optString("settings"), 0));
            if (!v13.isEmpty()) {
                JSONObject v10 = new JSONObject(v13);
                PreferenceManager v9 = PreferenceManager.getInstance();
                v9.setAdBlockEnabled(v10.optBoolean("AdBlock"));
                v9.setAnimEnabled(v10.optBoolean("anim"));
                v9.setBlock3rdPartyCookiesEnabled(v10.optBoolean("block3rdpartycookies"));
                v9.setLocalAdBlockEnabled(v10.optBoolean("localAdb"));
                v9.setBookmarksStyle(v10.optInt("bookmarksStye"));
                v9.setBlockImagesEnabled(v10.optBoolean("blockimages"));
                v9.setClearCacheExit(v10.optBoolean("cache"));
                v9.setClearCookiesExitEnabled(v10.optBoolean("clearCookiesExit"));
                v9.setClearFormdataExitEnabled(v10.optBoolean("clearFormdataExit"));
                v9.setClearHistoryExitEnabled(v10.optBoolean("clearHistoryExit"));
                v9.setClearWebStorageExitEnabled(v10.optBoolean("clearStorageExit"));
                v9.setColorModeEnabled(v10.optBoolean("colormode"));
                v9.setCookiesEnabled(v10.optBoolean("cookies"));
                v9.setDoNotTrackEnable(v10.optBoolean("donottrack"));
                v9.setDownloadDirectory(v10.optString("download"));
                v9.setFlashSupport(v10.optInt("enableflash"));
                v9.setFullScreenEnabled(v10.optBoolean("fullscreen"));
                v9.setHideStatusBarEnabled(v10.optBoolean("hidestatus"));
                v9.setHideUnderlineEnabled(v10.optBoolean("hideunderline"));
                v9.setHomepage(v10.optString("home"));
                v9.setImageSwitchEnabled(v10.optBoolean("imageswitch"));
                v9.setIncognitoModeEnabled(v10.optBoolean("incognitoMode"));
                v9.setIncognitoCookiesEnabled(v10.optBoolean("incognitocookies"));
                v9.setJavaScriptEnabled(v10.optBoolean("java"));
                v9.setLocationEnabled(v10.optBoolean("location"));
                v9.setNightModeEnabled(v10.optBoolean("nightmode"));
                v9.setOpenTimes(v10.optInt("opentimes"));
                v9.setOverviewModeEnabled(v10.optBoolean("overviewmode"));
                v9.setPopupsEnabled(v10.optBoolean("newwindows"));
                v9.setRemoveIdentifyingHeadersEnabled(v10.optBoolean("removeidentifyingheaders"));
                v9.setRenderingMode(v10.optInt("renderMode"));
                v9.setRuequstDesktopSiteEnabled(v10.optBoolean("requestdesktopsite"));
                v9.setRestoreLostTabsEnabled(v10.optBoolean("restoreclosed"));
                v9.setSaveFormdataEnabled(v10.optBoolean("saveformdata"));
                v9.setSavePasswordsEnabled(v10.optBoolean("passwords"));
                v9.setScreenOrientation(v10.optInt("screenOrientation"));
                v9.setSearchChoice(v10.optInt("search"));
                v9.setSearchHintEnabled(v10.optBoolean("searchhint"));
                v9.setSearchUrl(v10.optString("searchurl"));
                v9.setTextEncodingChoice(v10.optInt("textencoding"));
                v9.setTextReflowEnabled(v10.optBoolean("textreflow"));
                v9.setTextSize(v10.optInt("textsize"));
                v9.setUrlBoxChoice(v10.optInt("urlbox"));
                v9.setUserAgentChoice(v10.optInt("agentchoose"));
                v9.setUseWideViewportEnabled(v10.optBoolean("wideviewport"));
                v9.setVolumeScrollEnabled(v10.optBoolean("volume"));
                v9.setWebIntentEnabled(v10.optBoolean("webintent"));
                v9.setWakeLockEnabled(v10.optBoolean("wakelock"));
                v9.setKeyBackChoice(v10.optInt("keyback"));
                v9.setKeyForwardChoice(v10.optInt("keyforward"));
                v9.setKeyHomeChoice(v10.optInt("keyhome"));
                v9.setKeyTabChoice(v10.optInt("keytab"));
                v9.setKeyMenuChoice(v10.optInt("keymenu"));
                v9.setGestureToolbarLeftChoice(v10.optInt("gesturetoolbarleft"));
                v9.setGestureToolbarRightChoice(v10.optInt("gesturetoolbarright"));
                v9.setSearchTimes(v10.optInt("searchtimes"));
                v9.setLinksTimes(v10.optInt("linkstimes"));
                v9.setUIChoice(v10.optInt("ui"));
                v9.setAddonsScreenshotEnabled(v10.optBoolean("addonscreenshot"));
                v9.setAddonsTranslateEnabled(v10.optBoolean("addontranslate"));
                v9.setAddonsViewSourceEnabled(v10.optBoolean("addonviewsource"));
                v9.setQuickBackEnabled(v10.optBoolean("quickback"));
            }
        } catch (Exception v4) {
            v4.printStackTrace();
            return v12;
        }

        return true;
    }
}

